package com.zbf.线程池;

import java.util.concurrent.*;

/**
 * @author: LI-CI-GAO
 * 作者: licigao
 * 日期: 2021/8/14  10:53
 * 描述:
 */
public class TestXianChengChi {

    public static void main(String[] args) {
        //不推荐这种方式
       /// Executors.newScheduledThreadPool(5);

        LinkedBlockingDeque<Runnable> linkedBlockingDeque=new LinkedBlockingDeque<>();

        //推荐
        ArrayBlockingQueue arrayBlockingQueue=new ArrayBlockingQueue(2);
        ThreadPoolExecutor threadPoolExecutor=new ThreadPoolExecutor(
                //核心线程数
                2,
                //最大线程数
                2,
                //线程存活的时间
                50,
                //线程的存活时间的单位
                TimeUnit.SECONDS,
                //工作队列
                arrayBlockingQueue,
                new MyRejectedHandler(linkedBlockingDeque)
                );



        for (int i=0;i<20;i++){
            threadPoolExecutor.execute(new MyRunable01(i));
        }



        while (true){


            try {
                linkedBlockingDeque.pop().run();
            }catch (Exception e){
                 break;
            }

        }

        //关闭线程池
        threadPoolExecutor.shutdown();




    }

}
